package com.health.mapp.impl;

import com.health.db.model.RegisterOrder;
import com.health.db.service.order.IRegisterOrderService;
import com.health.db.service.sm.IRongService;
import com.health.db.service.user.IUserLISTService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.RateOrderReq;
import com.health.mapp.bean.RateOrderResp;
import com.health.mapp.utils.Constant;
import com.health.mapp.utils.DateUtils;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 *  此接口提供给用户操作
 *  用户订单进行评价操作，目前不限制何时调用
 *   注：缺少融云消息推送
 * @author HiRoad
 * 
 * @pramati
orderId	String	Y	订单号
userId	String	Y	用户号
docId	String	Y	医生号
star	Int	Y	星级，五星5表示
describe	String	N	评价描述
 *
 */
public class RateOrderImpl implements ActionInterface {
	
	//service import
	private IRegisterOrderService registerOrderService ;
	private IUserLISTService userLISTService  ;
	private IRongService rongService  ; 
	
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		RateOrderReq req = (RateOrderReq) reqBean; 
		RateOrderResp _resp = new RateOrderResp();
		Long orderId = req.getOrderId();
		//Long  docId =req.getDocId();
		int star =   req.getStar();
		Long userId = req.getUserId();
		if (userId==0||star==0||orderId==0||star>5) {
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return _resp;
		}else{
			
	       RegisterOrder  currRegisterOrder  =registerOrderService.selectSimpleSingleByOrderId(orderId);
	       
			//判断订单状态
			if (currRegisterOrder==null) {
				_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_3001);
				_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_3001_NOTE);
				return _resp;
			}
			//是否评价标识
			short evaluateFlag=currRegisterOrder.getEvaluateFlag()==null?0:currRegisterOrder.getEvaluateFlag();
			//判断类型，状态必须是订单未被评价才可以操作
			if (evaluateFlag!=Constant.CONSTANTS_ORDER_IS_COMMENT_0) {
				_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_3004);
				_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_3004_NOTE);
				return _resp;
			}
			
			//入参
			//只对评价做更新，其他不做
			currRegisterOrder.setUpdateUserid(userId);
			currRegisterOrder.setEvaluateScore((short) star);
			currRegisterOrder.setEvaluateDescribe(req.getDescribe());
			//标识是否评价为已评价
			currRegisterOrder.setEvaluateFlag(Constant.CONSTANTS_ORDER_IS_COMMENT_1);
			currRegisterOrder.setUpdateDate(DateUtils.now());
			
			//待评价状态先做进订单中，以后剥离
			currRegisterOrder.setRunStatus(Constant.CONSTANTS_ORDER_RUNSTATUS_DES_5);
			currRegisterOrder.setRunstatusid(Constant.CONSTANTS_ORDER_RUNSTATUS_ID_5);
			 
			registerOrderService.updateOrder4Comment(currRegisterOrder);
			
			String groupId = String.valueOf(orderId);
			rongService.dismissGroup(String.valueOf(userId), groupId);
			
		}
		
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
 
		return _resp;
	}
	
	public IRegisterOrderService getRegisterOrderService() {
		return registerOrderService;
	}


	public void setRegisterOrderService(IRegisterOrderService registerOrderService) {
		this.registerOrderService = registerOrderService;
	}


	public IUserLISTService getUserLISTService() {
		return userLISTService;
	}


	public void setUserLISTService(IUserLISTService userLISTService) {
		this.userLISTService = userLISTService;
	}

	/**
	 * @return the rongService
	 */
	public IRongService getRongService() {
		return rongService;
	}

	/**
	 * @param rongService the rongService to set
	 */
	public void setRongService(IRongService rongService) {
		this.rongService = rongService;
	}
	

	
	

}
